package com.wanxi.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ResultDto<T> {
    private Integer code;
    private String msg;
    private Integer count;
    private T data;

    /**
     * 返回消息
     * @param msg
     * @return
     */
    public static ResultDto getInstance(String msg) {
        return getInstance(0, msg, 0, null);
    }

    /**
     * 查询总条数：影响的条数
     * @param count
     * @return
     */
    public static ResultDto getInstance(Integer count) {
        return getInstance(0, "", count, null);
    }

    /**
     * 不用查询分页
     * @param data
     * @return
     */
    public static ResultDto getInstance(Object data) {
        return getInstance(0, "", 0, data);
    }

    /**
     * 针对有分页的情况，查询所有数据
     * @param count
     * @param data
     * @return
     */
    public static ResultDto getInstance(Integer count, Object data) {
        return getInstance(0, "", count, data);
    }

    private static ResultDto getInstance(Integer code, String msg, Integer count, Object data) {
        return ResultDto.builder()
                .code(code)
                .count(count)
                .msg(msg)
                .data(data)
                .build();
    }
}
